import { Client, Account, ID } from 'appwrite'
import { Server } from '@configs/server.js'

const client = new Client()
  .setEndpoint(Server.endpoint)
  .setProject(Server.project)

const account = new Account(client)

export const createAccountApi = async ({ email, password }) => {
  return await account.create(ID.unique(), email, password)
}

export const verificationApi = () => {
  const promise = account.createVerification('http://localhost:3000/login')
  promise.then(
    function (response) {
      console.log('createVerification', response) // Success
    },
    function (error) {
      console.log(error) // Failure
    }
  )
}

export const loginEmailApi = async ({ email, password }) => {
  return await account.createEmailSession(email, password)
}
